//instanceof运算符用于检测构造函数的prototype属性是否出现在某个实例对象的原型链上。
//instanceof运算符只能用于检查对象是否是某个构造函数的实例，不能用于基本类型（字符串、数字）的检查

function myInstanceOf(obj, constructor) {
  let proto = Object.getPrototypeOf(obj);
  while (proto) {
    if (proto === constructor.prototype) {
      return true;
    }
    proto = Object.getPrototypeOf(proto);
  }
  return false;
}

function Animal(){}
function Cat(){}
Cat.prototype = new Animal(); //prototype is an object, not a function, so it has access to everything it's declared on.
var cat = new Cat();
console.log(cat instanceof Cat);
console.log(cat instanceof Animal);